@echo off

setlocal

call "%%CONTOOLS_OLD_ROOT%%/stresc.bat" /v "" STRING_ESCAPED
set ERRORLEVEL_RETURNED=%ERRORLEVEL%
set STRING_EVALUATED=%STRING_ESCAPED%

if %TESTLIB__OVERALL_TESTS% GTR %TESTLIB__CURRENT_TESTS% (
  set "TEST_REPORT_PREFIX_STR=%TESTLIB__OVERALL_TESTS%`%TESTLIB__CURRENT_TESTS%"
) else set "TEST_REPORT_PREFIX_STR=%TESTLIB__CURRENT_TESTS%"

if %ERRORLEVEL_RETURNED% NEQ %STRING_LEN% (
  "%CONTOOLS_UTILITIES_BIN_ROOT%/contools/envvarcmp.exe" __STRING__ STRING_EVALUATED "" ^
    "FAILED: %TEST_REPORT_PREFIX_STR%: (%ERRORLEVEL_RETURNED% == %STRING_LEN%) RESULT=`{0}` REFERENCE=`${STRING_ESCAPED}`" ^
    "FAILED: %TEST_REPORT_PREFIX_STR%: (%ERRORLEVEL_RETURNED% == %STRING_LEN%) RESULT=`{0}` REFERENCE=`${STRING_ESCAPED}` (`{0hs}` != `{1hs}`)"
  echo.
  exit /b 1
)

"%CONTOOLS_UTILITIES_BIN_ROOT%/contools/envvarcmp.exe" __STRING__ STRING_EVALUATED "" ^
  "PASSED: %TEST_REPORT_PREFIX_STR%: STRING_LEN=%STRING_LEN% RESULT=`{0}`" ^
  "FAILED: %TEST_REPORT_PREFIX_STR%: STRING_LEN=%STRING_LEN% RESULT=`{0}` REFERENCE=`${STRING_ESCAPED}` (`{0hs}` != `{1hs}`)"
if %ERRORLEVEL% NEQ 0 (
  echo.
  exit /b 2
)

exit /b 0
